<template>
  <div class="login">
    <el-form
      :model="numberValidateForm"
      ref="numberValidateForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item
        label="用户名"
        prop="age"
      >
        <el-input
          type="name"
          v-model.number="numberValidateForm.name"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="密码"
        prop="pwd"
      >
        <el-input
          type="password"
          v-model.number="numberValidateForm.pwd"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()"
          >登陆</el-button
        >
        <el-button @click="resetForm()">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      numberValidateForm: {
        name: "",
        pwd:""
      },
    };
  },
  methods: {
    submitForm() {
      let name = this.numberValidateForm.name;
      let pwd = this.numberValidateForm.pwd;
      this.axios.post("/api/login",{name,pwd}).then((res)=>{
        console.log(res.data);
        if(res.data.code===200){
          alert(res.data.msg)
          localStorage.setItem("token",res.data.token);
          this.$router.push("/")
        }else{
          alert(res.data.msg);
        }
      })
    },
    resetForm() {
      console.log("bbbb");
    },
  },
};
</script>

<style lang="scss" scoped>
  .login{
    width: 500px;
    margin: 150px auto;
  }
</style>